import 'dart:async';
import 'package:flutter/material.dart';
import 'package:tv_friso_screen/login_page.dart';
import 'package:tv_friso_screen/utils/share_pre_utils.dart';

import 'home_main_page.dart';
import 'home_page.dart';

class WelComePage extends StatefulWidget {
  const WelComePage({super.key});

  @override
  State<WelComePage> createState() => _WelComePageState();
}

class _WelComePageState extends State<WelComePage> {
  Timer? mTimer;
  var text = "跳过3s";

  void startTimer(int count) {
    mTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
      count--;

      setState(() {
        text = "跳过${count.toString()}s";
      });

      if (count == 0) {
        mTimer!.cancel();

        if (SharePreUtils.getToken().isNotEmpty) {
          //直接进入首页
          Navigator.of(context).pushAndRemoveUntil(
              MaterialPageRoute(builder: (context) => const HomeMainPage()),
              (route) => false);
        } else {
          //进入登录页面
          Navigator.of(context).pushAndRemoveUntil(
              MaterialPageRoute(builder: (context) => const HomeMainPage()),
              (route) => false);
        }
      }
    });
  }

  @override
  void initState() {
    super.initState();
    startTimer(1); //倒计时3秒
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
        height: double.infinity,
        width: double.infinity,
      ),
    );
  }
}
